package cc.autoapi.pucong.auto.flow.core.flow.execNode.eventBus.test;


import cc.autoapi.pucong.auto.flow.core.flow.execNode.eventBus.IPublisher;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.eventBus.PublishMsg;
import cc.autoapi.pucong.auto.flow.core.flow.execNode.eventBus.PublisherImp;

/**
 * @description:
 * @author: cong.pu
 * @create: 2024-09-25 15:43
 **/
public class Start {
    public static void main(String[] args) {
        IPublisher musciPublisher = new PublisherImp("music");
        new SubscriberImp("music");
        new SubscriberImp("book");
        // 第一次调用线程池执行任务时，线程池需要消耗一定时间预热（我这大概40毫秒）
        musciPublisher.publicMessageByAsync(new StringPublishMsg("线程池预热"));
        long start = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            musciPublisher.publicMessageByAsync(new StringPublishMsg("来自musicPublisher的同步消息"));
        }
        long end = System.currentTimeMillis();
        System.out.println("用时：" + (end - start) + "毫秒");
    }

    private static class StringPublishMsg extends PublishMsg {
        private String msg;

        public StringPublishMsg(String msg) {
            this.msg = msg;
        }
    }
}
